color lineColor = color(0, 0, 0);

public class StickMan {

  Node trunkWorld  = new Node(new PVector(0, 0), 0.0);

    Polygon trunk(int x, int y, int large) {

      ArrayList<PVector> points = new ArrayList<PVector>();
      points.add(new PVector(x, y));
      points.add(new PVector(x, y+large));
      Polygon trunk = new Polygon(points, backgroundColor, lineColor);
      return trunk;
    }


  Polygon head(int x, int y, int widthHead) {
    ArrayList<PVector> points = new ArrayList<PVector>();
    points.add(new PVector(x, y));
    points.add(new PVector(x+widthHead, y));
    points.add(new PVector(x+widthHead, y-widthHead));
    points.add(new PVector(x, y-widthHead));
    Polygon head = new Polygon(points, backgroundColor, lineColor);
    return head;
  }


  Polygon leg(int x, int y, int large) {

    ArrayList<PVector> points = new ArrayList<PVector>();
    points.add(new PVector(x, y));
    points.add(new PVector(x, y+large));
    Polygon leg = new Polygon(points, backgroundColor, lineColor);
    return leg;
  }


  Polygon arm(int x, int y, int large) {

    ArrayList<PVector> points = new ArrayList<PVector>();
    points.add(new PVector(x, y));
    points.add(new PVector(x, y+large));
    Polygon arm = new Polygon(points, backgroundColor, lineColor);
    return arm;
  }


  Polygon hand(int x, int y, int large) {

    ArrayList<PVector> points = new ArrayList<PVector>();
    points.add(new PVector(x, y));
    points.add(new PVector(x, y+large));
    Polygon hand = new Polygon(points, backgroundColor, lineColor);
    return hand;
  }

 public Node create(ArrayList<Button> buttons, int BUTTON_SIZE) {
    int TRUNK_X = 50;
    int TRUNK_Y = 50;
    int LEG_LENGTH = 80;
    int TRUNK_LENGTH = 80;
    int ARM_LENGTH = 45;
    Polygon trunk = stickMan.trunk(TRUNK_X, TRUNK_Y, TRUNK_LENGTH);
    trunkWorld.addFigure(trunk);  

    Node headWorld = new Node(trunkWorld, new PVector(TRUNK_X, TRUNK_Y), 0.0);
    Polygon head = stickMan.head(-25, 0, 45);
    headWorld.addFigure(head);

    Node rightLegWorld = new Node(trunkWorld, new PVector(TRUNK_X, TRUNK_Y+TRUNK_LENGTH), -QUARTER_PI/2);
    Polygon leg = stickMan.leg(0, 0, LEG_LENGTH);
    rightLegWorld.addFigure(leg);

    Node leftLegWorld = new Node(trunkWorld, new PVector(TRUNK_X, TRUNK_Y+TRUNK_LENGTH), QUARTER_PI/2);
    leg = stickMan.leg(0, 0, LEG_LENGTH);
    leftLegWorld.addFigure(leg);

    Node rigthArm = new Node(trunkWorld, new PVector(TRUNK_X, TRUNK_Y+TRUNK_LENGTH/4), -5*QUARTER_PI/2);
    Polygon amr = stickMan.arm(0, 0, ARM_LENGTH);
    rigthArm.addFigure(amr);


    Node leftArm = new Node(trunkWorld, new PVector(TRUNK_X, TRUNK_Y+TRUNK_LENGTH/4), 5*QUARTER_PI/2);
    amr = stickMan.arm(0, 0, ARM_LENGTH);
    leftArm.addFigure(amr);

    Node rightHand = new Node(rigthArm, new PVector(0, ARM_LENGTH), -PI/2);
    Polygon hand = stickMan.hand(0, 0, 20);
    rightHand.addFigure(hand);

    pg =  createGraphics(500, 500);

    
    PImage icon = loadImage("icons/default.jpg");
    PImage overIcon = loadImage("icons/pressed-default.jpg");
    /*Botones para cada una de las partes del cuerpo del muñeco*/
    
    Action rotate = new RotateWorld(rigthArm, -PI, 0.01);
    PImage iconRigthArm = loadImage("icons/arm.jpg");
    PImage overRigthArm = loadImage("icons/OverArm.png");
    Button button1 = new Button(iconRigthArm, overRigthArm, 0, 0, BUTTON_SIZE, rotate);
    buttons.add( button1);
    
    PImage iconLeftArm = loadImage("icons/armLeft.jpg");
    PImage overLeftArm = loadImage("icons/OverArmLeft.png");
    rotate = new RotateWorld(leftArm);
    Button button2 = new Button(iconLeftArm, overLeftArm, 80, 0, BUTTON_SIZE, rotate);
    buttons.add( button2);
    
    PImage iconHand = loadImage("icons/hand.jpg");
    PImage overHand = loadImage("icons/OverHand.png");
    rotate = new RotateWorld(rightHand, -PI, 0.01);
    Button button3 = new Button(iconHand, overHand, 40, 0, BUTTON_SIZE, rotate);
    buttons.add( button3);
    
    PImage iconHead = loadImage("icons/head.jpg");
    PImage overHead = loadImage("icons/Overhead.png");
    rotate = new RotateWorld(headWorld, -PI/2 , PI/2);
    Button button4 = new Button(iconHead, overHead, 120, 0, BUTTON_SIZE, rotate);
    buttons.add( button4);
    
    PImage iconLeftLeg = loadImage("icons/leg.jpg");
    PImage overLeftLeg = loadImage("icons/OverLeg.png");
    rotate = new RotateWorld(leftLegWorld);
    Button button5 = new Button( iconLeftLeg , overLeftLeg, 160, 0, BUTTON_SIZE, rotate);
    buttons.add( button5);
    
    PImage iconRigthLeg = loadImage("icons/legRigth.jpg");
    PImage overRigthLeg = loadImage("icons/OverLegRigth.png");
    rotate = new RotateWorld(rightLegWorld);
    Button button6 = new Button(iconRigthLeg , overRigthLeg, 200, 0, BUTTON_SIZE, rotate);
    buttons.add( button6);
    
    PImage iconTranslateTrunk = loadImage("icons/move.jpg");
    PImage overTranslateTrunk = loadImage("icons/OverMove.png");
    TranslateWorld translate = new TranslateWorld(trunkWorld);
    Button button7 = new Button(iconTranslateTrunk, overTranslateTrunk, 240, 0, BUTTON_SIZE, translate);
    buttons.add( button7);
    
    
    

    for (Button button : buttons) {
      button.drawButton(false);
    }
    return trunkWorld;
  }
}



